var dictTypeCtrl  = new XFApp.client();

XFApp.client.prototype.dictType = {
		successCode : 10000,	
		dictTypePage : null,
		urlItems : {
			initListURL: basePath+"/dict/loadDictType",
			deleteDictTypeURL:basePath+"/dict/updateDictType",
		},	
		
		load : function (){
			
            _this = this;
			
			var entity = {				
				dicttypename:$("#dicttypename").val(),
				dicttypecode:$("#dicttypecode").val(),
				isremoved:0,
			}
			
			if(!!_this.dictTypePage){
				_this.dictTypePage.page("remote",0,entity);
			}else{
				_this.dictTypePage = $("#page").page({
				pageSize : 10,
				remote: {
					url: _this.urlItems.initListURL,
			        params: entity, 
			        success: function (data, pageIndex) {
			        	if(data.code==_this.successCode){			        		
			        		if(null == data 
									|| null == data.result 
										|| null == data.result.itemList
											|| data.result.itemList.length < 1){
			        			$("#data_grid").html('<tr><td align="center" colspan="11">暂无数据</td></tr>');
			        		}else{
			        			$("#data_grid").html($("#dataTmp").render(data.result.itemList));
			        		}			        		
			        	}else{
			        		window.webDialogUtil.alert("提示",data.msg);			        		   
			        	}
			        },
			        error : function(){
			        	
			        	window.webDialogUtil.alert("提示",data.msg);			      	  
			        }
				},
				firstBtnText : '首页',
				lastBtnText : '尾页',
				prevBtnText : '上一页',
				nextBtnText : '下一页',
				showInfo : true,
				showJump : true,
				jumpBtnText : '跳转',
				showPageSizes : true,
				infoFormat : '共{pageCount}页'
			});	
		   }			
		},
		
		remove: function(option){
						
			var type = $("#remove").attr("title");			
			webAlert({
	                title:'提示',
	                content:'确认执行'+type+'操作吗?',
	                opacity:.5,
	                bg:"gray",
	                width:300,
	                height:10,
	                button:[
	                        {
	                        name:"确定",
	                        callback:function(){
	                        	_this.removeConfirm(option);
	                        	this.close();
	                        }
	                        },{
	                        name:"取消",
	                        callback:function(){
	                      	  this.close();
	                        }
	                        }]
	        });
			
		},
		
		removeConfirm : function (dicttypeid){
			
			var params = {
				dicttypeid:dicttypeid,
				isremoved : 1,
			};
			
			$.ajax ({
				url :_this.urlItems.deleteDictTypeURL,
				data : params,
				dataType : "json",
				type : 'post',
				success : function(data) {
					if(data.code == _this.successCode){						
						window.webDialogUtil.alert("提示",data.msg);	
						_this.load();
		        	}else{
		        		
		        		window.webDialogUtil.alert("提示",data.msg);		        		
		        	}
				}
			});		
			
		},		
		
		event : function(){
			_this = this;			
			$("#btnSearch").on("click",function(){
				_this.load();
			});
		},
		
		
};


$(function(){
	dictTypeCtrl.dictType.load();
	dictTypeCtrl.dictType.event();
});